package com.zhaoxi.project.hrp.controller;

import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.hrp.service.LeadService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 客户跟踪Controller
 */
@Tag(name = "Lead", description = "客户线索跟踪线索")
@RestController
@RequestMapping("/hrp/lead")
public class LeadController extends BaseService {
  @Autowired
  private LeadService leadService;

  //  获列表
  @PreAuthorize("@ss.hasPermi('hrp:lead:list')")
  @GetMapping("/getList")
  public PageData getList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null) {
      this.startPage();
    }
    return this.responses(leadService.getList(pd));
  }

  //  获行数
  @PreAuthorize("@ss.hasPermi('hrp:lead:list')")
  @GetMapping("/getCount")
  public PageData getCount(Map map) {
    PageData pd = this.getPageData(map);
    return leadService.getCount(pd);
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('hrp:lead:add')")
  @Log(title = "线索", businessType = BusinessType.INSERT)
  @PostMapping
  public PageData add(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return leadService.add(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('hrp:lead:edit')")
  @Log(title = "线索", businessType = BusinessType.UPDATE)
  @PutMapping
  public PageData edit(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return leadService.edit(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('hrp:lead:del')")
  @Log(title = "线索", businessType = BusinessType.DELETE)
  @DeleteMapping("id/{id}")
  public PageData del(@PathVariable Long id) {
    return leadService.del(id);
  }

//================线索跟踪日志记录表

  //  获列表
  @PreAuthorize("@ss.hasPermi('hrp:lead:list')")
  @GetMapping("/getCommentList")
  public PageData getCommentList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null) {
      this.startPage();
    }
    return this.responses(leadService.getCommentList(pd));
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('hrp:lead:add')")
  @Log(title = "线索", businessType = BusinessType.INSERT)
  @PostMapping("/comment")
  public PageData addComment(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return leadService.addComment(pd);
  }
}
